using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace shfa.snomtastic.data
{
    public partial class SqlDataProvider
    {

        public Guid InsertEventLog(Guid phoneId, Guid userId, string macAddress, string ipAddress, string userAgent, string eventSource, string eventMessage, string eventType, DateTime eventDate)
		{
            return new Guid(Convert.ToString(SqlHelper.ExecuteScalar(ConnectionString, "sp_EventLogInsert", GetNull(phoneId), GetNull(userId), macAddress, ipAddress, userAgent, eventSource, eventMessage, eventType, GetNull(eventDate))));
		}

        public int UpdateEventLog(Guid eventLogId, Guid phoneId, Guid userId, string macAddress, string ipAddress, string userAgent, string eventSource, string eventMessage, string eventType, DateTime eventDate)
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_EventLogUpdate", GetNull(eventLogId), GetNull(phoneId), GetNull(userId), macAddress, ipAddress, userAgent, eventSource, eventMessage, eventType, GetNull(eventDate)));
		}

        public int DeleteEventLog(Guid eventLogId) 
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_EventLogDelete", eventLogId));
		}

        public DataRow SelectEventLog(Guid eventLogId) 
        {    
			DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, "sp_EventLogSelect", eventLogId);
            if (ds.Tables.Count > 0)
                if (ds.Tables[0].Rows.Count > 0)
                    return ds.Tables[0].Rows[0];

            return null;
		}

		public DataTable SelectEventLogs() 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_EventLogSelectAll").Tables[0];
        }

		public DataTable SelectEventLogsByUser(Guid userId) 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_EventLogSelectByUser", userId).Tables[0];
        }

    }

}
